package com.lc.sell.controller;



import com.lc.sell.entity.Review;
import com.lc.sell.service.ReviewService;
import com.lc.sell.vo.ResultVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.models.auth.In;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 龙晨
 * @since 2022-04-06 09:27:10
 */
@Api(tags = "评论控制")
@RestController
@RequestMapping("review")
public class ReviewController {

    @Autowired
    private ReviewService reviewService;
    
    @GetMapping("reviewList")
    public ModelAndView toReview(){
        ModelAndView mv = new ModelAndView();
        mv.setViewName("page/review");
        return mv;
    }

    @ApiOperation(value = "提交评论")
    @PostMapping("comment")
    public ResultVo reviewComment(@RequestBody Review review){
        return reviewService.insetReview(review);
    }

    @ApiOperation(value = "查看是否评论")
    @GetMapping("selreview")
    public ResultVo selreview(@RequestParam String orderId,@RequestParam String userId){
        return reviewService.selReviewStatus(orderId, userId);
    }

    @ApiOperation(value = "查看订单评论")
    @GetMapping("selReviewList")
    public ResultVo selReviewList(HttpServletRequest request){
        Integer mid = (Integer) request.getSession().getAttribute("mid");
        return reviewService.selReviewList(String.valueOf(mid));
    }


    @ApiOperation(value = "根据订单号查看订单评论")
    @GetMapping("selReviewByOrderId")
    public ResultVo selReviewByOrderId(@RequestParam String orderId){
        return reviewService.selReviewByOrderId(orderId);
    }
}
